# -*- coding: utf-8 -*-

# Copyright (c) Huoty - All rights reserved
# Author: Huoty <sudohuoty@gmail.com>
# CreateTime: 2016-10-15 15:42:37

"""产生随机字符串"""

from __future__ import division, absolute_import

import string
import random


def _choice(chars, length):
    return ''.join(random.SystemRandom().choice(chars) for _ in range(length))


def gen_str(length):
    """产生随机字符串"""
    return _choice(string.ascii_letters + string.digits, length)


def gen_lower_str(length):
    """产生只包含小写字母的字符串"""
    return _choice(string.ascii_lowercase, length)


def gen_upper_str(length):
    """产生只包含大写字母的字符串"""
    return _choice(string.ascii_uppercase, length)


def gen_digit_str(length):
    """产生只包含数字的字符串"""
    return _choice(string.digits, length)


def gen_letter_str(length):
    """产生只白包含大小写字母的字符串"""
    return _choice(string.ascii_letters, length)


def gen_lower_digit_str(length):
    """产生只包含小写字母和数字的字符串"""
    return _choice(string.ascii_lowercase + string.digits, length)


def geen_upper_digit_str(length):
    """产生只包含大写字母和数字的字符串"""
    return _choice(string.ascii_uppercase + string.digits, length)


def gen_hex_str(length):
    """产生十六进程随机字符串"""
    return _choice("abcdef1234567890", length)


def gen_key(length):
    """产生随机 Key"""
    return _choice("wertuoasdfhklzxcvbnm1234567890", length)


# Script starts from here

if __name__ == "__main__":
    pass
